//
//  KTSearchBar.m
//  KTVShopProduct
//
//  Created by paeanSs on 2017/11/8.
//  Copyright © 2017年 paeanSs. All rights reserved.
//

#import "KTSearchBar.h"

@implementation KTSearchBar

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.placeholder = @"搜索";
        self.keyboardType = UIKeyboardTypeDefault;
        self.backgroundImage = [self getImageWithColor:[UIColor clearColor] andHeight:44.0f];
        //设置顶部搜索栏的背景色
//        [self setBackgroundColor:UIColorFromHex(0xf0f0f0)];
        //设置顶部搜索栏输入框的样式
        UITextField *searchField = [self valueForKey:@"_searchField"];
        searchField.layer.borderWidth = 0.5f;
        searchField.layer.borderColor = [[UIColor whiteColor] CGColor];//UIColorFromHex(0xdfdfdf)
        searchField.layer.cornerRadius = 5.f;
        searchField.layer.masksToBounds = YES;
        searchField.textColor = [UIColor blackColor];
        [searchField setValue:NormalDefalutColor forKeyPath:@"_placeholderLabel.textColor"];
        searchField.font = [UIFont systemFontOfSize:13];
        searchField.backgroundColor = UIColorFromHex(0xf0f0f0);
    }
    return self;
}

- (UIImage*) getImageWithColor:(UIColor*)color andHeight:(CGFloat)height
{
    CGRect r= CGRectMake(0.0f, 0.0f, 1.0f, height);
    UIGraphicsBeginImageContext(r.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, r);
    
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}


@end
